package com.atguigu.springcloud.controller;

import cn.hutool.core.util.IdUtil;
import com.atguigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
//@DefaultProperties(defaultFallback = "generalFallBack")
public class OrderHystrixController {
    @Autowired
    public PaymentService paymentService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String payment_OK(@PathVariable("id") Integer id){
        String result=paymentService.payment_OK(id);
        log.info("/consumer/payment/hystrix/ok/"+id+",返回结果:"+result);
        return result;
    }

    @GetMapping("/consumer/payment/hystrix/timeOut/{id}")
    /*@HystrixCommand(fallbackMethod = "paymentFallBack",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value = "2000")
    })
    */
   //  @HystrixCommand
    public String payment_TimeOut(@PathVariable("id") Integer id) {
        String result=paymentService.payment_TimeOut(id);
        log.info("/consumer/payment/hystrix/timeOut/"+id+",返回结果:"+result);
        return result;
    }


    public String paymentFallBack(Integer id){
        return "消费者调用异常或者超时，随机码:"+ IdUtil.randomUUID();
    }
    public String generalFallBack(){
        return "通用的消费者调用异常或者超时，随机码:"+ IdUtil.randomUUID();
    }

}
